﻿
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using Model;
using MsDAL;
using System.ComponentModel;
using Components;

namespace ServiceHelper
{
    [DataObjectAttribute]
    public partial class Sys5a10Manager : Sys5a10Base
    {
        private static Sys5a10Manager _entity;

        public static Sys5a10Manager Entity
        {
            get
            {
                if (_entity == null)
                    _entity = new Sys5a10Manager();
                return _entity;
            }
        }

        #region 个人代码
        /// <summary>
        /// 报表中心的页面数据源
        /// </summary>
        /// <param name="tb"></param>
        /// <param name="usercode"></param>
        /// <returns></returns>
        public DataTable[] GetDataSource(Hashtable tb, string usercode)
        {
            if (null == tb || !tb.ContainsKey("pagename")) return null;

            string pagename = Validation.ToString(tb["pagename"]);

            List<DataTable> tables = new List<DataTable>();

            //加载页面搜索框的布局
            tables.Add(Sys5a01Manager.Entity.GetList(pagename, "Summary"));

            DataTable suls = sys5a10Dal.LoadSalustion(usercode, pagename, "Detail");
            //加载方案搜索框
            tables.Add(suls);

            if (null != suls && 0 != suls.Rows.Count)
            {
                //得到透视表的布局信息
                Hashtable where = new Hashtable();
                where["listid"] = suls.Rows[0]["listid"]; //默认提取第一条样式

                tables.Add(CommonManager.Entity.ExecDBFun("GetPivotLayout", where));
                where = null;
            }

            return tables.ToArray();
        }

        public string SaveSln(Hashtable tb, DataTable dtl, DataTable deldata, string action, string usercode)
        {
            List<SqlApp> lst = new List<SqlApp>();

            if (action == "S") //另存为
            {
                Sys5a10 model = new Sys5a10();
                model.Listid = Sys0a60Manager.Entity.CreateSn("sys5a10_listid", usercode);
                model.Ispublic = Validation.ToString(tb["public"]);
                model.Pagelistid = Sto5a00Manager.Entity.GetKeyByPageName(Validation.ToString(tb["page"]));
                model.Providname = Validation.ToString(tb["name"]);
                model.Usercode = "n" == model.Ispublic.ToLower() ? usercode : null;

                lst.Add(this.Add(model));

                Sys5a11 mdtl = null;
                foreach (DataRow dr in dtl.Rows)
                {
                    mdtl = new Sys5a11();
                    mdtl.Prolistid = Sys0a60Manager.Entity.CreateSn("sys5a11_listid", usercode);
                    mdtl.Columname = Validation.ToString(dr["name"]);
                    mdtl.Fmid = model.Listid;
                    mdtl.Ppt1 = Validation.ToString(dr["area"]);
                    mdtl.Ppt2 = Validation.ToString(dr["show"]);

                    lst.Add(Sys5a11Manager.Entity.Add(mdtl));
                }
            }
            else if (action == "A") //保存
            {
                string listid = Validation.ToString(tb["name"]);
                //显示明细
                lst.Add(Sys5a11Manager.Entity.DeleteDetail(listid));

                Sys5a11 mdtl = null;
                foreach (DataRow dr in dtl.Rows)
                {
                    mdtl = new Sys5a11();
                    mdtl.Prolistid = Sys0a60Manager.Entity.CreateSn("sys5a11_listid", usercode);
                    mdtl.Columname = Validation.ToString(dr["name"]);
                    mdtl.Fmid = listid;
                    mdtl.Ppt1 = Validation.ToString(dr["area"]);
                    mdtl.Ppt2 = Validation.ToString(dr["show"]);

                    lst.Add(Sys5a11Manager.Entity.Add(mdtl));
                }
            }
            else if (action == "D")
            {
                string listid = Validation.ToString(tb["name"]);
                //显示明细
                lst.Add(Sys5a11Manager.Entity.DeleteDetail(listid));

                Sys5a10 model = new Sys5a10();
                model.Listid = listid;

                lst.Add(this.Delete(model));
            }

            return CommonManager.Entity.SaveData(lst);
        }

        #endregion
    }
}



